package com.university.mentalhealthplatform.studentV3.controller;

import com.university.mentalhealthplatform.appModels.Test;
import com.university.mentalhealthplatform.studentV3.dto.TestDTOV3;
import com.university.mentalhealthplatform.studentV3.service.TestServiceV3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v3/tests")
public class TestControllerV3 {

    @Autowired
    private TestServiceV3 testServiceV3;

    @GetMapping
    public List<Test> getAllTests() {
        return testServiceV3.findAll();
    }

    @GetMapping("/{id}")
    public Test getTestById(@PathVariable Integer id) {
        return testServiceV3.findById(id);
    }

    @GetMapping("/random")
    public ResponseEntity<List<TestDTOV3>> getRandomTests(@RequestParam(defaultValue = "25") int count) {
        List<TestDTOV3> randomTests = testServiceV3.getRandomTests(count);
        return ResponseEntity.ok(randomTests);
    }


    @PostMapping
    public Test createTest(@RequestBody Test test) {
        return testServiceV3.save(test);
    }

    @DeleteMapping("/{id}")
    public void deleteTest(@PathVariable Integer id) {
        testServiceV3.deleteById(id);
    }

    // 其他可能的端点
}

